#!/bin/bash
#curl -s https://gitee.com/huyiru/huyiru/raw/master/paping.sh | bash 
IP=$(ip addr | grep inet |grep -v "127.0.0.1" |grep -v inet6|awk '{print $2}'|awk -F "/" '{print $1}'| head -1|awk -F "." '{print $1"."$2"."$3}')
PORT=(
#59000
22
51000
)
which paping || (curl -o /bin/paping  https://gitee.com/huyiru/huyiru/raw/master/paping;chmod +x /bin/paping)
for ip in `seq 1 255`
do
{
ping -c 1 $IP.$ip > /dev/null 2>&1   
if [ $? -eq 0 ] 
then
    echo $IP.$ip UP >>/tmp/ip_up.out

    declare -A A
    for SERVER in ${PORT[@]}
    do
       # 跳过被注释
        echo $SERVER | grep -E '^#' >/dev/null 2>&1
        if [ "$?" -eq 0 ];then
           continue
        fi

        array=($(echo $SERVER | tr ',' ' '))
        A['PORT']=${array[0]}
          paping -c 1 $IP.$ip -p ${A['PORT']} 
          if [ $? -eq 0 ]; then
            echo "$IP.$ip  ${A['PORT']} open" >>/tmp/paping_port_open.out
          #else
            #echo "$IP.$ip  ${A['PORT']} close">>/tmp/paping_port_close.out
          fi
    done

else
   echo $IP.$ip down >>/tmp/ip_down.out
fi
}&
done